package com.sc.VenusQueryBeta.presenter.account;

import com.hengjun.kingstar.sdk.utils.LogUtil;
import com.sc.VenusQueryBeta.contract.account.CurrencyContract;
import com.sc.VenusQueryBeta.model.account.CurrencyModel;
import com.sc.VenusQueryBeta.model.bean.account.CurrencyBean;

import io.reactivex.functions.Consumer;

/**
 * Created by Administrator on 2018/11/8.
 * 幣種presenter
 */

public class CurrencyPresenter extends CurrencyContract.CurrencyPresenter {
    @Override
    protected CurrencyContract.ICurrencyModel getModel() {
        return CurrencyModel.newInstance();
    }

    @Override
    public void onStart() {

    }
    public static  CurrencyPresenter newInstance(){
        return new CurrencyPresenter();
    }

    /**
     * 獲取幣種
     * @param serverAddress
     * @param projectName
     * @param serverPort
     * @param clientindex
     * @param recognitionValue
     */
    @Override
    public void getcurrency(String serverAddress, String projectName, int serverPort, int clientindex, int recognitionValue) {
        if (mIView == null || mIModel == null)
            return;
        mRxManager.register(mIModel.getcurrency(serverAddress,projectName,serverPort,clientindex,recognitionValue).subscribe(new Consumer<CurrencyBean>() {
            @Override
            public void accept(CurrencyBean currencyBean) throws Exception {
                if (mIView != null)
                    mIView.showgetCurrencyData(currencyBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                if (mIView != null) {
                    //      if (mIView.isVisiable())
                    mIView.showToast("Network error");
                    LogUtil.e("zhehsiwodesd"+throwable.getMessage());
                    mIView.showNetworkError(throwable);
                }
            }
        }));
    }
}
